const mongoose = require("mongoose");
const db = require("./db/index");
const BookModel = require("./models/BookModel");

db(
  () => {
    console.log("连接成功");

    // 新增
    BookModel.create(
      {
        name: "西游记111",
        author: "吴承恩",
        price: 19.9,
      },
      (err, data) => {
        if (err) {
          return console.log(err);
        }
        console.log(data);
        // 关闭数据库连接(项目运行中不会添加)
        // mongoose.disconnect();
      }
    );
  },

  () => {
    console.log("连接失败");
  }
);
